<?php

/**
 * 
 * @author yuxun
 *
 */
class IosService extends Service {
	
	public static function getUrl($packet,$version){
// 		$name_port = 'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER["SERVER_PORT"];
// 		$urlDta = array();
// 		$urlDta['GameNoticeUrl'] = $name_port.'/api/?r=notice/getLastNotice&channel_id=';
// 		$urlDta['GameSeverListUrl'] = 'http://mgs1.s10.q-dazzle.com:25331/v1/server_list/get/?channel_id=';
// 		$urlDta['LoginServerAddress'] = 'mgs1.s10.q-dazzle.com';
// 		$urlDta['LoginServerPort'] = '10232';

		$name_port = 'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER["SERVER_PORT"];
		$GameNoticeUrl = $name_port.'/api/?r=notice/getLastNotice&channel_id=';
		$GameSeverListUrl = 'http://mgs1.s10.q-dazzle.com:25331/v1/server_list/get/?channel_id=';
		$LoginServerAddress = 'mgs1.s10.q-dazzle.com';
		$LoginServerPort = '10232';
		$ResourceUpdateAddress = 'http://res.yiyun.s10.q-dazzle.com/download.php';
		$ChannelPlatformId = 1;
		$Channel = '11753';

		if($packet == ''){
			$json_arr = array('errcode'=>-1,'msg'=>'need to parameter packet','data'=>'');
			return $json_arr;
		}
		
		if($version == ''){
			$json_arr = array('errcode'=>-1,'msg'=>'need to parameter version','data'=>'');
			return $json_arr;
		}
		

		//查询库里是否存在该记录，不存在返回 $urlDta，存在不返回
		$modIosExamine = new ModIosExamine();
		$list_obj = $modIosExamine->findAllByAttributes(array('packet' => $packet,'v_num'=>$version));
		if(!$list_obj){  //不存在记录
			$json_arr = array('errcode'=>0,'msg'=>'记录不存在','data'=>'');
		}else{
			$modIosExamineCat = new ModIosExamineCat();
			$url_obj = $modIosExamineCat->findAllByAttributes(array('id' => $list_obj[0]->category));
			if(!$url_obj){
				$json_arr = array('errcode'=>0,'msg'=>'地址分类不存在','data'=>'');
				return $json_arr;
			}
			
			$urlDta = array();
			$urlDta['GameNoticeUrl'] = $url_obj[0]->game_notice_url == ''? $GameNoticeUrl : $url_obj[0]->game_notice_url;
			$urlDta['GameSeverListUrl'] = $url_obj[0]->game_sever_list_url == ''? $GameSeverListUrl : $url_obj[0]->game_sever_list_url;
			$urlDta['LoginServerAddress'] = $url_obj[0]->login_server_address == ''? $LoginServerAddress : $url_obj[0]->login_server_address;
			$urlDta['LoginServerPort'] = $url_obj[0]->login_server_port == ''? $LoginServerPort : $url_obj[0]->login_server_port;
			$urlDta['ResourceUpdateAddress'] = $url_obj[0]->resource_update_address == ''? $ResourceUpdateAddress : $url_obj[0]->resource_update_address;
			$urlDta['ChannelPlatformId'] = $url_obj[0]->channel_platform_id == ''? $ChannelPlatformId : $url_obj[0]->channel_platform_id;
			$urlDta['Channel'] = $list_obj[0]->channel == ''? $Channel : $list_obj[0]->channel;
			
			if($list_obj[0]->type == 1){  //审核服
				$json_arr = array('errcode'=>1,'msg'=>'审核服','data'=>$urlDta);
			}else if($list_obj[0]->type == 2){ //正式服
				$json_arr = array('errcode'=>2,'msg'=>'正式服','data'=>'');
			}else{
				$json_arr = array('errcode'=>0,'msg'=>'记录不存在','data'=>'');
			}
		}

		return $json_arr;	
		
	}
	
	public static function getRechargeUrl($channel,$packet){
		if($channel == ''){
			$json_arr = array('errcode'=>-1,'msg'=>'need to parameter channel','data'=>'');
			return $json_arr;
		}
		
		if($packet == ''){
			$json_arr = array('errcode'=>-1,'msg'=>'need to parameter packet','data'=>'');
			return $json_arr;
		}
		$modRechargeUrl = new ModRechargeUrl();
		$list_obj = $modRechargeUrl->findByAttributes(array('channel' => $channel,'packet'=>$packet));
		if(!$list_obj){  //不存在记录
			$json_arr = array('errcode'=>0,'msg'=>'记录不存在','data'=>'');
		}else{
			$urlDta = array();
			$urlDta['1000'] = $list_obj->money_18;
			$urlDta['1001'] = $list_obj->money_6;
			$urlDta['1002'] = $list_obj->money_30;
			$urlDta['1003'] = $list_obj->money_68;
			$urlDta['1004'] = $list_obj->money_128;
			$urlDta['1005'] = $list_obj->money_198;
			$urlDta['1006'] = $list_obj->money_328;
			$urlDta['1007'] = $list_obj->money_648;
			
			$json_arr = array('errcode'=>1,'msg'=>'查询成功','data'=>$urlDta);
		}
		return $json_arr;
	}
	
	

}